using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using CoreLib;

namespace Gizmo
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Box : Microsoft.Xna.Framework.DrawableGameComponent
    {
        private VertexPositionColor[] pointList;
        private int points=12;
        private short[] lineStripIndices;
        private float size;

        public float Size
        {
            get { return size; }
            set { size = value; }
        }
        public Box(Game game)
            : base(game)
        {

            Engine.game.Components.Add(this);
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
                  
            base.Initialize();
        }
        public void CreateVertices()
        {
            // TODO: Add your initialization code here
            pointList = new VertexPositionColor[points];


            pointList[0] = new VertexPositionColor(new Vector3(-Size, -Size, -Size), Color.White);
            pointList[1] = new VertexPositionColor(new Vector3(-Size, -Size, Size), Color.White);
            pointList[2] = new VertexPositionColor(new Vector3(Size, -Size, Size), Color.White);
            pointList[3] = new VertexPositionColor(new Vector3(Size, -Size, -Size), Color.White);

            pointList[4] = new VertexPositionColor(new Vector3(-Size, Size, -Size), Color.White);
            pointList[5] = new VertexPositionColor(new Vector3(-Size, Size, Size), Color.White);
            pointList[6] = new VertexPositionColor(new Vector3(Size, Size, Size), Color.White);
            pointList[7] = new VertexPositionColor(new Vector3(Size, Size, -Size), Color.White);

            lineStripIndices = new short[24] { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 };
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }
        public override void Draw(GameTime gameTime)
        {
            for (int i = 0; i < pointList.Length; i++)
    pointList[i].Color = Color.Red;

    Engine.game.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
    PrimitiveType.LineList,
    pointList,
    0,   // vertex buffer offset to add to each element of the index buffer
    8,   // number of vertices to draw
    lineStripIndices,
    0,   // first index element to read
    12 // number of primitives to draw
    );
for (int i = 0; i < pointList.Length; i++)
    pointList[i].Color = Color.White;
        }
    }
}
